package com.ay.weixin.interceptor;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Random;

import javax.servlet.ServletException;

import org.apache.velocity.tools.generic.NumberTool;
import org.lizar.controller.intercepter.EventInterceptor;
import org.lizar.controller.loader.BasicLoader;
import org.lizar.log.Log;
import org.lizar.log.Logger;
import org.lizar.util.StringHelper;

import com.ay.weixin.config.ProjectConfig;


public class Interceptor implements EventInterceptor{
	private Log log=Logger.newInstance(this.getClass());
	private NumberTool numberTool=new NumberTool();
	private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	@Override
	public void before(BasicLoader bl) throws ServletException,
			IOException {
		bl.setAttr("rand", new Random().nextInt());
		String user_agent=bl.getHeader("user-agent");
		if(StringHelper.isNotNull(user_agent)&&(user_agent.toLowerCase().contains("micromessenger")||user_agent.toLowerCase().contains("windows phone"))){
			bl.setAttr("from_weixin", true);
		} 
		
		bl.setAttr("NumberTool",numberTool);
		bl.setAttr("dateFormat",dateFormat);
		
	}

	
	
	@Override
	public void after(BasicLoader el) throws ServletException,
			IOException {
	}



	@Override
	public void init_property() throws Exception {
	}


	
	
}
